<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>作业01.格式化时间_2024-01-26</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=0">
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

    </style>
    <script>
        let now = new Date()
        let formatDate = (date) => {
            let d = new Date(date);
            let year = d.getFullYear();
            let month = d.getMonth() + 1;
            let da = d.getDate();
            let day = d.getDay();
            console.log(day)
            let hours = d.getHours();
            let minutes = d.getMinutes();
            let seconds = d.getSeconds();
            let str = `${year}年${month < 10 ? "0" + month : month}月${da}日 星期`
            switch (day) {
                case 0:
                    str += "日"
                    break;
                case 1:
                    str += "一"
                    break;
                case 2:
                    str += "二"
                    break;
                case 3:
                    str += "三"
                    break;
                case 4:
                    str += "四"
                    break;
                case 5:
                    str += "五"
                    break;
                case 6:
                    str += "六"
                    break;

            }
            str += ` ${hours}:${minutes}:${seconds}`
            return str;
        }


        console.log(formatDate(now));
    </script>
</head>
<body>

</body>
</html>